package com.gitee.huxing.course;

import cn.hutool.core.date.DateUtil;
import com.gitee.huxing.framework.redis.RedisWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.annotation.Resource;
import java.io.*;

@Slf4j
@SpringBootApplication
public class SpringBootOrderApplication implements CommandLineRunner {

    @Resource
    RedisWrapper redisWrapper;

    public static void main(String[] args) throws IOException {
        SpringApplication.run(SpringBootOrderApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        // 写入服务的启动时间
        redisWrapper.setObject("order-service", DateUtil.now());
        // TODO: 因为没有通过数据库管理，所以每次启动给一个库存总量
        redisWrapper.setObject("3f5c7eaa55e94e3793c42ed0d962159d", 10);
        log.info("订单服务启动: {}", redisWrapper.getString("order-service"));
    }
}
